package com.company.Lab2;

import java.util.Scanner;

public class RelationalitatiiBernoulli {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        double[][] bernoulli;
        double probability;
        double[] sum;
        double[] prod;
        double preSum = 0;
        double max;
        int r, c;

//        Read matrix size
        System.out.print("Intoduceti numarul de randuri : ");
        r = scanner.nextInt();
        System.out.print("Introduceti numarul de coloane : ");
        c = scanner.nextInt();
//        Init Arrays
        bernoulli = new double[r][c];
        sum = new double[r];
        prod = new double[r];
//        Read matrix
        System.out.println("Introduceti datele matricii : ");
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print("[" + i + "][" + j + "] : ");
                bernoulli[i][j] = scanner.nextDouble();
            }
        }
//        Calc probability
        probability = (double) 1 / c;
        System.out.println("Probabilitatea pentru matrice este : " + probability);
//        Calc Sum
        for (int i = 0; i < r; i++) {
            preSum = 0;
            for (int j = 0; j < c; j++) {
                preSum += bernoulli[i][j];
            }
            sum[i] = preSum;
        }
//        Print Sum
        System.out.println("Suma :");
        for (double s : sum) {
            System.out.print("\t" + s);
        }
        System.out.println();
//        Calc prod
        for (int i = 0; i < sum.length; i++) {
             prod[i] = sum[i] * probability;
        }
//        Calc max from prod
        max = prod[0];
        for (int i = 0; i< prod.length; i++){
            max = Math.max(max,prod[i]);
        }
//        Print max
        System.out.println("Valoarea Bernoulli este : " + max);
    }
}
